<template>
  <div class="explain">
    <Breadcrumb>
      <BreadcrumbItem>活动设置</BreadcrumbItem>
      <BreadcrumbItem>活动说明</BreadcrumbItem>
    </Breadcrumb>
    <div ref="editor"></div>
    <Button type="default" style="margin-top: 10px;" v-on:click="setExplain">确认</Button>
  </div>
</template>

<script>
import Common from '../../common/common.js';
import E from 'wangeditor';
export default {
  name: 'explain',
  data(){
    return {
      //--公共--
      session:{},  //登录信息
      //--参数--
      activity_id:0,  //活动id
      //--活动说明--
      explain:'',   //活动说明内容
      //--editor--
      editor:null,   //富文本编辑器对象
    }
  },
  created(){
    this.activity_id = sysinfo.activity_id;
  },
  mounted(){
    this.createEditor();
    this.getExplain();
  },
  methods:{
    //获取活动说明内容
    getExplain(){
      Axios.post(sysinfo.url,Qs.stringify({
          pages:'activity',
          doing:'easyFind',
          activity_id:this.activity_id,
          return:['explain']
      }))
              .then((res)=>{
                if(res.data.status == 'success'){
                  var data = res.data.data;
                  this.explain = data.explain;
                  this.editor.txt.html(data.explain);
                }
              })
              .catch(error=>console.log(error));
    },
    //编辑活动说明
    setExplain(){
      Axios.post(sysinfo.url,Qs.stringify({
        pages:'activity',
        doing:'edit',
        activity_id:this.activity_id,
        data:{explain:this.explain}
      }))
              .then((res)=>{
                if(res.data.status == 'success'){
                  this.$Message.success('设置成功');
                }else{
                  this.$Message.error('设置失败');
                }
              })
              .catch(error=>console.log(error));
    },
    //创建富文本编辑器
    createEditor(){
      this.editor = new E(this.$refs.editor);
      this.editor.customConfig.uploadImgServer = sysinfo.url;
      this.editor.customConfig.uploadImgParams = {
        pages:'editor',
        doing:'uploadEditorImage'
      }
      this.editor.customConfig.zIndex = 2;
      this.editor.customConfig.onchange = (html)=>{
        this.explain = html;
      }
      this.editor.create();
    }
  }
}
</script>

<style scoped>
  .explain{
    padding:0 10px 10px 10px;
  }
</style>
